<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import ReCol from "@/components/ReCol";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { GetAllStation } from '@/utils/api/dispatch/station'
import stationList from './components/stationList.vue'
import { useTranslationLang } from "@/layout/hooks/useTranslationLang";
const { locale } = useTranslationLang();
import { useI18n } from "vue-i18n";
const { t } = useI18n();

const props = withDefaults(defineProps<FormProps>(), {
    formInline: () => ({
        code: "",
        warehouseid: null,
        shelvesid: null,
        layer: null,
        row: null,
        length: null,
        width: null,
        height: null,
        bearing: null,
        status: 1,
        sort: null,
        note: "",
        prestaid: null,
        lochigh: 0,
        lifthigh: 0,
        liftside: 0,
        lrdistance: null,
        lrdistance2: null,
        vehicletype: "",
        attribute: "",
        auxiliary: "",
        correct: null,
        // stationList: [],
    }),
    statusSelect: [],
    attributeSelect: [],
    rackselect: [],
    stationSelect: [],
    rotateList: [],
    agvModel: []
});

const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

const statusSelect = ref(props.statusSelect);
const rackselect = ref(props.rackselect);
const stationSelect = ref(props.stationSelect);
const prestaidList = ref([]);
const agvModel = ref(props.agvModel);
const attributeSelect = ref(props.attributeSelect);
const lrdistanceList = ref(props.lrdistanceList)


function getRef() {
    return ruleFormRef.value;
}

defineExpose({ getRef });

const rotationangleList = [
    {
        name: t('racklocations.left'),
        code: 1
    }
    , {
        name: t('racklocations.right'),
        code: 2
    }]
// const lrdistanceList = [0, 1.33]
onMounted(async () => {
    // console.log('props=>', props.formInline);

    // 货位前站点
    let { Content }: any = await GetAllStation({ status: 1, stationType: 0 })
    prestaidList.value = Content
})
</script>

<template>
    <el-form ref="ruleFormRef" :model="newFormInline" :rules="formRules" label-width="100px"
        :label-position="locale === 'en' ? 'top' : 'right'">
        <el-row :gutter="30">
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.locationCode')" prop="code">
                    <el-input v-model="newFormInline.code" clearable />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.belongingShelf')" prop="shelvesid">
                    <el-select v-model="newFormInline.shelvesid" style="width:100%">
                        <el-option v-for="item in rackselect" :key="item.id" :label="item.name" :value="item.id" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.floorLevel')" prop="layer">
                    <el-input-number v-model="newFormInline.layer" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.numberOfColumns')" prop="row">
                    <el-input-number v-model="newFormInline.row" controls-position="right" />
                </el-form-item>
            </re-col>
            <!-- <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="长度" prop="length">
          <el-input-number v-model="newFormInline.length" controls-position="right" placeholder="请输入长度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="宽度" prop="width">
          <el-input-number v-model="newFormInline.width" controls-position="right" placeholder="请输入宽度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="高度" prop="height">
          <el-input-number v-model="newFormInline.height" controls-position="right" placeholder="请输入高度" />
        </el-form-item>
      </re-col>
      <re-col :value="12" :xs="24" :sm="24">
        <el-form-item label="承重" prop="bearing">
          <el-input-number v-model="newFormInline.bearing" controls-position="right" placeholder="请输入承重" />
        </el-form-item>
      </re-col> -->
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.accessHeight')" prop="lochigh">
                    <el-input-number v-model="newFormInline.lochigh" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.liftingHeight')" prop="lifthigh">
                    <el-input-number v-model="newFormInline.lifthigh" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.compensationForPickUp')" prop="lrdistance">
                    <el-select v-model="newFormInline.lrdistance" allow-create filterable style="width:100%">
                        <el-option v-for="item in lrdistanceList" :key="item.Id" :label="Number(item.Name)"
                            :value="Number(item.Name)" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.compensationForReleaseOfGoods')" prop="lrdistance2">
                    <el-select v-model="newFormInline.lrdistance2" allow-create filterable style="width:100%">
                        <el-option v-for="item in lrdistanceList" :key="item.Id" :label="Number(item.Name)"
                            :value="Number(item.Name)" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.longitudinalSeparation')" prop="liftside">
                    <el-input-number v-model="newFormInline.liftside" controls-position="right" />
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.rotationDirection')" prop="rotationangle">
                    <!-- <el-input-number v-model="newFormInline.rotationangle" controls-position="right" placeholder="请输入旋转角度" /> -->
                    <el-select v-model="newFormInline.rotationangle" filterable style="width:100%">
                        <el-option v-for="item in rotationangleList" :key="item.code" :label="item.name"
                            :value="item.code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.agvModel')" prop="vehicletype">
                    <el-select v-model="newFormInline.vehicletype" style="width:100%">
                        <el-option v-for="item in agvModel" :key="item.Code" :label="item.Name" :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.status')" prop="status">
                    <el-select v-model="newFormInline.status" style="width:100%">
                        <el-option :label="t('racklocations.idle')" :value="1" />
                        <el-option :label="t('racklocations.disable')" :value="2" />
                        <el-option :label="t('racklocations.locked')" :value="3" />
                        <el-option :label="t('racklocations.cargoAlreadyLoaded')" :value="4" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.cargoLocationStation')" prop="auxiliary">
                    <el-select v-model="newFormInline.auxiliary" filterable style="width:100%">
                        <el-option v-for="item in stationSelect" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.stationInFrontOfTheCargoLocation')" prop="prestaid">
                    <el-select v-model="newFormInline.prestaid" filterable clearable style="width:100%">
                        <el-option v-for="item in prestaidList" :key="item.stationid" :label="item.stationname"
                            :value="item.stationid" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.locationType')" prop="attribute">
                    <el-select v-model="newFormInline.attribute" filterable style="width:100%">
                        <el-option v-for="item in attributeSelect" :key="item.Id" :label="item.Name"
                            :value="item.Code" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.correct')" prop="correct ">
                    <el-select v-model="newFormInline.correct" style="width:100%">
                        <el-option :label="t('racklocations.empty')" :value="null" />
                        <el-option :label="t('racklocations.close')" :value="0" />
                        <el-option :label="t('racklocations.turnOn')" :value="1" />
                    </el-select>
                </el-form-item>
            </re-col>
            <re-col :value="12" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.sort')" prop="sort">
                    <el-input-number v-model="newFormInline.sort" controls-position="right" />
                </el-form-item>
            </re-col>
            <!-- <re-col :value="24" :xs="24" :sm="24">
                <el-form-item label="货位列表" prop="stationList" style="font-weight: 700;" class="callbox">
                    <stationList :data="newFormInline.stationList" :stationSelect="stationSelect"></stationList>
                </el-form-item>
            </re-col> -->
            <re-col :value="24" :xs="24" :sm="24">
                <el-form-item :label="t('racklocations.remarks')" prop="note">
                    <el-input v-model="newFormInline.note" clearable type="textarea" />
                </el-form-item>
            </re-col>
        </el-row>
    </el-form>
</template>

<style lang="scss" scoped>
.el-radio {
    margin-right: 16px;
}
</style>
